<template>
	<view class='goodList'>
		<scroll-view scroll-y="true" scroll-with-animation='true' style="height: 100%;">

			<block v-for="(item,index) in bastList" :key="index">
				<view @click="goDetail(item)" class='item acea-row row-between-wrapper' hover-class="none">
					<view class='pictrue'>
						<image :src='item.image'></image>
						<span class="pictrue_log pictrue_log_class"
							v-if="item.activity && item.activity.type === '1' && $permission('seckill')">{{$t(`秒杀`)}}</span>
						<span class="pictrue_log pictrue_log_class"
							v-if="item.activity && item.activity.type === '2' && $permission('bargain')">{{$t(`砍价`)}}</span>
						<span class="pictrue_log pictrue_log_class"
							v-if="item.activity && item.activity.type === '3' && $permission('combination')">{{$t(`拼团`)}}</span>
					</view>
					<view class='underline'>
						<view class='text'>
							<view class='line1'>
								<view class="tag_class" :class="[{'tag_purple':item.sales_method==2},{'tag_red':item.sales_method==3}]" v-if="item.sales_method!=0">
									{{item.sales_method==1?'现货':item.sales_method==2?'半成品':'预售'}}
								</view>
								{{item.store_name}}
							</view>
							<view class='money flex_sb'>
								<view style="flex:1">
									<!-- {{$t(`￥`)}}<text class='num'>{{item.price}}</text> -->
									<view class="text_info">
										克重：<text>约{{item.attrs[0].weight}}克</text>
									</view>
									<view class="text_info" v-if="Number(item.labor_costs)">
										工费：<text class="sign"
											v-if="authenticate_type==1">{{item.labor_costs}}/{{item.labor_costs_unit_text}}</text>
										<text class="sign" v-else>?/{{item.labor_costs_unit_text}}</text>
									</view>
									<view class="text_info" v-if="Number(item.attach_labor_costs)">
										附加工费：<text class="sign"
											v-if="authenticate_type==1">{{item.attach_labor_costs}}/{{item.attach_labor_costs_unit_text}}</text>
										<text class="sign" v-else>?/{{item.attach_labor_costs_unit_text}}</text>
									</view>
								</view>
								<!-- 搜索页面的商品可直接添加到购物车 -->
								<view  v-if="pageName=='search'">
									<view @tap.stop="addCartChange(item, index)">
										<view class="rd-24rpx w-44 h-44 cart_btn">
											<view class="flex-center cart-btn">
												<text class="iconfont icon-ic_increase-2 fs-26"></text>
											</view>
										</view>
										<!-- <view class="rd-24rpx w-44 h-44" :style="[btnTextColor]" v-else>
											<view class="flex-center cart-btn">
												<text class="iconfont icon-ic_ShoppingCart1 fs-26"></text>
											</view>
										</view> -->
									</view>
								</view>
							</view>
							<view class='vip-money acea-row row-middle'
								v-if="item.is_vip && item.vip_price && item.vip_price > 0">
								{{$t(`￥`)}}{{item.vip_price || 0}}
								<image src='../../static/images/vip.png'></image><text class='num'>
									{{$t(`已售`)}}{{item.sales}}{{$t(item.unit_name)}}</text>
							</view>
							<view class='vip-money acea-row row-middle' v-else><text class='num'>
									{{$t(`已售`)}}{{item.sales}}{{$t(item.unit_name)}}</text></view>
						</view>
					</view>
					<!-- <view class='iconfont icon-gouwuche cart-color acea-row row-center-wrapper'></view> -->
				</view>
			</block>
		</scroll-view>
		<productWindow :price_type="storeInfo.price_type" :authenticate_type="authenticate_type" :selectSku="selectSku" :attr="attr" :isShow='1' :iSplus='1' :iScart='1' :fangda="false" type="2" @myevent="onMyEvent"
					@ChangeAttr="ChangeAttr" @ChangeCartNum="ChangeCartNumDuo" @attrVal="attrVal" @iptCartNum="iptCartNum"
					@goCat="goCatNum" id='product-window'></productWindow>
		<authenticationMadal ref="authenticationMadalRef"></authenticationMadal>
	</view>
</template>

<script>
	import skuSelect from '@/mixins/skuSelect.js'
	import productWindow from '@/components/productWindow';
	import authenticationMadal from "@/components/authenticationModal/index.vue"
	import {
		mapGetters
	} from "vuex";
	import {
		goShopDetail,
		goPage
	} from '@/libs/order.js'
	import {
		getProductslist,
		getProductHot,
		getAttr
	} from '@/api/store.js';
	export default {
		components:{
			productWindow,
			authenticationMadal
		},
		computed: mapGetters(['uid','isLogin']),
		mixins: [skuSelect],
		props: {
			pageName: {
				type: String,
				default: '',
			},
			authenticate_type: {
				type: Number | String,
				default: 0,
			},
			status: {
				type: Number,
				default: 0,
			},
			bastList: {
				type: Array,
				default: function() {
					return [];
				}
			}
		},
		mounted() {
			setTimeout(()=>{
				console.log(this.authenticate_type,"--------");
			},3000)
		},
		data() {
			return {
				storeInfo: {},
				selectSku: {}, //选择的数据
				tempArr: [], //商品列表
				attr: {
					cartAttr: false,
					productAttr: [],
					productSelect: {}
				},
				productValue: [],
				attrValue: '', //已选属性
				id: 0 //商品id
			};
		},
		methods: {
			// 商品详情接口；
			getAttrs(id) {
				let that = this;
				getAttr(id, 0).then(res => {
					that.$set(that.attr, 'productAttr', res.data.productAttr);
					that.$set(that, 'id', res.data.productAttr[0].product_id);
					that.$set(that, 'productValue', res.data.productValue);
					that.$set(that, 'storeInfo', res.data.storeInfo);
					that.DefaultSelect();
				})
			},
			addCartChange(item, index) {
				if (this.authenticate_type != 1) {
					// 未认证则弹窗提醒认证
					return this.$refs.authenticationMadalRef.openHandle()
				}

				if (item.spec_type) {
					this.goCartDuo(item);
				} else {
					this.goCartDan(item, index);
				}

			},
			goDetail(item) {
				goPage().then(res => {
					goShopDetail(item, this.uid).then(res => {
						uni.navigateTo({
							url: `/pages/goods_details/index?id=${item.id}`
						})
					})
				})

			}

		}
	}
</script>

<style scoped lang='scss'>
	.cart_btn {
		color: #FFFFFF;
		background: linear-gradient(90deg, rgba(13, 13, 13, 1) 0%, rgba(0, 0, 0, 1) 100%);
		.cart-btn {
			width: 100%;
			height: 100%;
			.iconfont{
				position: unset !important;
				width: unset !important;
				height: unset !important;
			}
		}
		
	}

	.goodList .item {
		position: relative;
		padding-left: 30rpx;
	}

	.goodList .item .pictrue {
		width: 180rpx;
		height: 180rpx;
		position: relative;
	}

	.goodList .item .pictrue image {
		width: 100%;
		height: 100%;
		border-radius: 20rpx;
	}

	.goodList .item .pictrue .numPic {
		position: absolute;
		left: 7rpx;
		top: 7rpx;
		width: 40rpx;
		height: 40rpx;
		border-radius: 50%;
	}

	.goodList .item .underline {
		padding: 30rpx 30rpx 30rpx 0;
		border-bottom: 1px solid #f5f5f5;
	}

	.goodList .item:nth-last-child(1) .underline {
		border-bottom: 0;
	}

	.goodList .item .text {
		font-size: 30rpx;
		color: #222;
		width: 489rpx;
	}

	.goodList .item .text .money {
		font-size: 26rpx;
		/* font-weight: bold; */
		margin-top: 20rpx;
	}

	.goodList .item .text .money .sign {
		color: #D43030;
	}

	.goodList .item .text .money .num {
		font-size: 34rpx;
	}

	.goodList .item .text .vip-money {
		font-size: 24rpx;
		color: #282828;
		font-weight: bold;
		margin-top: 15rpx;
	}

	.goodList .item .text .vip-money image {
		width: 64rpx;
		height: 26rpx;
		margin-right: 8rpx;
		margin-left: 8rpx;
	}

	.goodList .item .text .vip-money .num {
		font-size: 22rpx;
		color: #aaa;
		font-weight: normal;
		margin-top: -2rpx;
		white-space: nowrap;

		text {
			white-space: nowrap;
		}

		~.num {
			margin-left: 22rpx;
		}
	}

	.goodList .item .iconfont {
		position: absolute;
		right: 30rpx;
		width: 50rpx;
		height: 50rpx;
		border-radius: 50%;
		font-size: 30rpx;
		bottom: 38rpx;
	}
</style>